<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="Cache-Control" content="No-Cache">
	<meta http-equiv="Pragma" content="No-Cache">

	<title>운세의 신</title>

	<link rel="stylesheet" type="text/css" href="/css/common.css">
	
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
	<script src="/js/common_basic.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			$("#keyword").focus();
			
			var idxs = $(".idx");
			
			var chkNoticeYn = $(".chkNoticeYn");
			var chkBestYn   = $(".chkBestYn");
			var chkSecretYn = $(".chkSecretYn");
			
			chkNoticeYn.each(function(index) {
				$(this).click(function() {
					var question = $(this).is(":checked") ? '공지를 등록합니까?' : '공지를 해제합니까?';
					changeType($(this), question, idxs.eq(index).val(), index);
				});
			});

			chkBestYn.each(function(index) {
				$(this).click(function() {
					var question = $(this).is(":checked") ? '베스트로 등록합니까?' : '베스트를 해제합니까?';
					changeType($(this), question, idxs.eq(index).val(), index);
				});
			});

			chkSecretYn.each(function(index) {
				$(this).click(function() {
					var question = $(this).is(":checked") ? '비밀로 등록합니까?' : '비밀을 해제합니까?';
					changeType($(this), question, idxs.eq(index).val(), index);
				});
			});
			
			
		});
		
		function changeType(obj, question, idx, index) {
			if (confirm(question)) {
				var notice_yn = $(".chkNoticeYn").eq(index).is(":checked") ? 'Y' : 'N';
				var best_yn   = $(".chkBestYn").eq(index).is(":checked")   ? 'Y' : 'N';
				var secret_yn = $(".chkSecretYn").eq(index).is(":checked") ? 'Y' : 'N';

				$.get(
					"/bbs/modify_type_ok",
					{'idx':idx,'notice_yn':notice_yn,'best_yn':best_yn,'secret_yn':secret_yn},
					function(result) {
						if (result == 'true') {
							alert('완료');
						} else {
							alert('실패');
						}
					}
				);
			} else {
				if (obj.is(":checked")) {
					obj.removeAttr('checked');
				} else {
					obj.attr('checked','checked');
				}
			}

//			alert(notice_yn+best_yn+secret_yn);

//			alert(idx);
		}
	
		function openDetail(idx) {
			window.open('/bbs/detail?idx='+idx, 'popup', 'width=650, height=650, toolbar=no,directories=no,scrollbars=yes,resizable=no,status=no,menubar=no,top=0,left=0');
		}

		function openNewArtist() {
			window.open('/star/starunse/register_form', 'popup', 'width=650, height=650, toolbar=no,directories=no,scrollbars=yes,resizable=no,status=no,menubar=no,top=0,left=0');
		}

		function remove(idx) {
			if (confirm('삭제?')) {
				document.frm2.idx.value = idx;
				document.frm2.submit();
			}
		}
		
		// 정렬
		function orderBy(order) {
			if (order == $("#order").val()) {
				if($("#sort").val() == 'asc') {
					$("#sort").val("desc");
				} else {
					$("#sort").val("asc");
				}
			} else {
				$("#order").val(order);
				$("#sort").val("asc");
			}
			$("#frm").submit();
		}
		
		// 페이지 이동
		function goPage(page) {
			$("#page").val(page);
			$("#frm").submit();
		}
	</script>
</head>
<body>


<div id="wrap">
	<!-- Header -->
	<? include_once $_SERVER['DOCUMENT_ROOT'].'/include/commons/header.php'; ?>
	<!--// Header -->
	
	<!-- Contents -->
	<div id="content">
		<h2>게시판 관리 - 리스트</h2>
		<div>
			<form method="get" name="frm" id="frm" action="/bbs">
				<select name="cate" id="cate" title="카테고리 선택">
					<option value="">전체</option>
<?
	$cate           = isset($_GET['cate']) ? $_GET['cate'] : '';
	$search_type    = isset($_GET['search_type']) ? $_GET['search_type'] : '';
	$search_keyword = isset($_GET['search_keyword']) ? $_GET['search_keyword'] : '';
?>
<?	foreach ($cates as $key => $value) : ?>
					<option value="<?=$key?>" <?=$key == $cate ? 'selected="selected"' : ''?>><?=$value?></option>
<?	endforeach ?>
				</select>
				<select name="search_type" id="search" title="검색어 분류선택">
					<option value="subject" <?=$search_type == 'subject' ? 'selected="selected"' : ''?>>제목</option>
					<option value="user_id" <?=$search_type == 'user_id' ? 'selected="selected"' : ''?>>작성자ID</option>
					<option value="content" <?=$search_type == 'content' ? 'selected="selected"' : ''?>>내용</option>
				</select>
				<input type="hidden" name="page" id="page" value="1" />
				<input type="text" name="search_keyword" id="search_keyword" value="<?=$search_keyword?>" />
				<input type="submit" value="검색"/> <input type="button" value="모두보기" onclick="location.href='/bbs'"/>
			</form>
		</div>
		<div>
			<table class="basicTable" width="100%" cellpadding="2" cellspacing="1" border="0">
				<thead>
					<tr>
						<th>IDX</th>
						<th>카테고리</th>
						<th>운세종류</th>
						<th>아이디</th>
						<th>닉네임</th>
						<th>제목</th>
						<th><a href="/bbs?search_type=notice_yn&search_keyword=Y&page=1" title="공지사항만 보기">공지</a></th>
						<th><a href="/bbs?search_type=best_yn&search_keyword=Y&page=1" title="베스트글만 보기">베스트</a></th>
						<th><a href="/bbs?search_type=secret_yn&search_keyword=Y&page=1" title="비밀글만 보기">비밀</a></th>
						<th>작성일</th>
						<th>상세보기</th>
					</tr>
				</thead>
				<tbody>
<?	foreach ($list as $item) : ?>
					<tr>
						<td align="center"><input type="hidden" class="idx" value="<?=$item['idx']?>" /><?=$item['idx']?></td>
						<td align="center"><?=$cates[$item['category']]?></td>
						<td align="center"><?=$item['service_name']?></td>
						<td align="center"><?=$item['user_id']?></td>
						<td align="center"><?=$item['nickname']?></td>
						<td align="left"><a href="http://www.unsin.co.kr/bbs/<?=$item['category']?>/read?idx=<?=$item['idx']?>" target="_blank"><?=$item['subject']?></a></td>
						<td align="center"><input type="checkbox" class="chkNoticeYn" <?=$item['notice_yn']=='Y'?'checked="checked"':''?>/></td>
						<td align="center"><input type="checkbox" class="chkBestYn"   <?=$item['best_yn']=='Y'?'checked="checked"':''?>/></td>
						<td align="center"><input type="checkbox" class="chkSecretYn" <?=$item['secret_yn']=='Y'?'checked="checked"':''?>/></td>
						<td align="center"><?=$item['create_dt']?></td>
						<td align="center"><button onclick="openDetail('<?=$item['idx']?>')">보기</button></td>
					</tr>
<?	endforeach ?>
				</tbody>
				<tfoot>
					<tr>
						<td colspan="10">
							<? include_once $_SERVER['DOCUMENT_ROOT'].'/include/board/page_navi.php'; ?>
						</td>
					</tr>
				</tfoot>
			</table>
		</div>
	</div>
	<!--// Contents -->
	
	<!-- Footer -->
	<? include_once $_SERVER['DOCUMENT_ROOT'].'/include/commons/footer.php'; ?>
	<!--// Footer -->
</div>
</body>
</html>